{#
/**
 * @file
 * Grid component
 *
 * See component.wingsuit.yml for usage.
 */
#}

{# SETTINGS #}
{% set columns = columns|default(2) %}
{% set columns_width = columns_width|default('equal') %}

{% set gutter = gutter|default('default') %}

{% set gutter_cell_classes = pattern_configuration('grid', '', 'gutter')[gutter]['cell'] %}
{% set gutter_container_classes = pattern_configuration('grid', '', 'gutter')[gutter]['container'] %}

{% set configuration = pattern_configuration('grid', '', 'columns')[columns][columns_width] %}

{% set classes = ([
  gutter_container_classes,
  'row'
]) | sort | join(' ') | trim %}

{% set attributes = attributes|default(create_attribute()).addClass(classes) %}

{# TEMPLATE #}
{% if configuration is not empty %}
  <div {{ attributes }}>
    {% block cells %}
      {% for cell_counter, cell in cells %}
        {% set column_i = (cell_counter % columns) + 1 %}
        {% set column_classes = configuration[column_i] is not empty ? configuration[column_i] : configuration['default'] %}
        {% set cell_attributes = create_attribute().
          addClass(
          [
            column_classes,
            gutter_cell_classes
          ] | sort | join(' ') | trim) %}
        {% block cell_outer %}
          <div {{ cell_attributes }}>
            {% block cell_inner %}
              {{ cell }}
            {% endblock %}
          </div>
        {% endblock %}
      {%- endfor -%}
    {% endblock %}
  </div>
{% else %}
  No configuration found for "{{ columns }}/{{ config }}".
{% endif %}
